program eva;
var yy,ii,a,n,m,x,d,s:integer;
procedure rei(var y,i:integer;n:integer);
var aa:array[1..3,1..2] of integer;
    k:integer;
begin
  if n=1 then
    begin
      y:=1;
      i:=0;
      exit;
    end;
  if n=2 then
    begin
      y:=0;
      i:=1;
      exit;
    end;
  y:=1;
  i:=1;
  aa[1,1]:=1;
  aa[1,2]:=0;
  aa[2,1]:=0;
  aa[2,2]:=1;
  for k:=3 to n do
    begin
      aa[3,1]:=aa[1,1]+aa[2,1];
      aa[3,2]:=aa[1,2]+aa[2,2];
      y:=y+aa[3,1];
      i:=i+aa[3,2];
      aa[1,1]:=aa[2,1];
      aa[1,2]:=aa[2,2];
      aa[2,1]:=aa[3,1];
      aa[2,2]:=aa[3,2];
    end;
end;
begin
  readln(a,n,m,x);
  rei(yy,ii,n-3);
  d:=round(((m-a)-yy*a)/ii);
  rei(yy,ii,x-2);
  writeln(ii*d+yy*a+a);
end.
